import '@babel/polyfill'
import Vue from 'vue'
import App from './App.vue'
import router from './router/router'
import store from './store/store'
import searchCommon from './util/searchCommon.js'
// import 'amfe-flexible'
import myPrint from '@/util/print'
import cascaderMulti from 'cascader-multi'
import 'element-ui/lib/theme-chalk/index.css'
import moment from 'moment'
import Viewer from 'v-viewer'
import ViewUI, { Message, Modal, Notice } from 'view-design'
import VueCookies from 'vue-cookies'
import VueI18n from 'vue-i18n'
import Router from 'vue-router'
import axios from './axios/axios'
import util from './util/util'

Vue.use(cascaderMulti)

import { OptionGroup, Option, Select, Table, TableColumn, MessageBox } from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'

Vue.use(Select)
Vue.use(Option)
Vue.use(OptionGroup)
Vue.use(Table)
Vue.use(TableColumn)

Vue.prototype.$msgbox = MessageBox
Vue.prototype.$alert = MessageBox.alert
Vue.prototype.$confirm = MessageBox.confirm
Vue.prototype.$prompt = MessageBox.prompt

import '@/filter/utils'
import focusable from 'vue-tv-focusable'

import Vue2OrgTree from 'vue2-org-tree'
import vant from './vant'

Vue.use(Vue2OrgTree)

Vue.use(vant)
Vue.use(focusable)

/**
 * 全局定义数据源
 */
import Print from '@/plugins/print'
import variable from '@/util/const'

Vue.prototype.$variable = variable
Vue.use(Viewer) // 注册
Viewer.setDefaults({
  Options: {
    'inline': true,
    'button': true,
    'navbar': true,
    'title': true,
    'toolbar': true,
    'tooltip': true,
    'movable': true,
    'zoomable': true,
    'rotatable': true,
    'scalable': true,
    'transition': true,
    'fullscreen': true,
    'keyboard': true,
    'url': 'data-source'
  }
})

import backLevel from './components/backLevel'
import bottomHandleWrap from './components/bottomHandleWrap'
import pageLeftTitle from './components/pageLeftTitle'

// 分页组件
import Pagination from './components/Pagination'

import '@/components/autoPlaceChildren'
import { Button, Cascader } from 'element-ui'

Vue.component('Pagination', Pagination)
Vue.component(Cascader.name, Cascader)
// Vue.use(DatePicker)
Vue.component(Button.name, Button)
Vue.component('backLevel', backLevel)
Vue.component('bottomHandleWrap', bottomHandleWrap)
Vue.component('pageLeftTitle', pageLeftTitle)
// Vue.component('curd',curd)
// Vue.use(Print);  //注册
// 导入自定义语言包
import en from './language/en-US'
import zh from './language/zh-CN'
import tw from './language/zh-TW'
// 导入view-design自带的
import iview_en from 'view-design/dist/locale/en-US'
import iview_zh from 'view-design/dist/locale/zh-CN'
import iview_tw from 'view-design/dist/locale/zh-TW'

import './directives/has'

Vue.use(Print)
Vue.use(ViewUI, {
  size: 'default',
  fontSize: '14px',
  table: {
    resizable: true
  }
})
Vue.use(searchCommon)
Vue.use(VueI18n)
Vue.locale = () => {
}
const messages = {
  'en_US': Object.assign(en, iview_en),
  'zh_CN': Object.assign(zh, iview_zh),
  'zh_TW': Object.assign(tw, iview_tw)
}

// 自动设置语言 获取本机语言
const navLange = navigator.language
const localLangel = (navLange === 'zh_CN' || navLange === 'en_US' || navLange === 'zh_TW') ? navLange : false
window.localStorage.setItem('language', localStorage.getItem('language') ? localStorage.getItem('language') : localLangel || 'zh_CN')
const lang = window.localStorage.getItem('language') || localLangel || 'zh_CN'

// Create VueI18n instance with options
const i18n = new VueI18n({
  locale: lang, // set locale
  messages // set locale messages
})

/* 解决路由重复点击问题*/
const routerPush = Router.prototype.push
Router.prototype.push = function push(location) {
  return routerPush.call(this, location).catch(error => error)
}

Vue.config.productionTip = false

// 挂载到prototype上，在组件中可以直接使用this.axios访问
Vue.prototype.axios = axios
// Vue.prototype.Mui = Mui;
Vue.prototype.util = util
Vue.prototype.searchCommon = searchCommon
Vue.prototype.$Message = Message
Vue.prototype.$Notice = Notice
Vue.prototype.$Modal = Modal
Vue.prototype.$myPrint = myPrint
Vue.use(VueCookies)
moment.locale(lang.toLocaleLowerCase())
Vue.prototype.$moment = moment
// Vue.prototype.$echarts = echarts;
new Vue({
  router,
  store,
  i18n,
  searchCommon,
  render: h => h(App)
}).$mount('#app')
